package com.example.administrator.myapplication;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.buildins.circlenavigator.CircleNavigator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    MagicIndicator mNewsTabLayout;

    ViewPager mNewsFragmentViewPager;

    List<Fragment> fragmentList;

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        mNewsTabLayout = findViewById(R.id.news_tab_layout);
        mNewsFragmentViewPager = findViewById(R.id.news_fragment_view_pager);


        fragmentList = new ArrayList<>();
        Bundle bundle = new Bundle();

        Fragment_one fragment_one = new Fragment_one();
        bundle.putString("one", "111111");
        fragment_one.setArguments(bundle);
        fragmentList.add(fragment_one);

        Fragment_two fragment_two = new Fragment_two();
        bundle.putString("two", "22222");
        fragment_two.setArguments(bundle);
        fragmentList.add(fragment_two);

        mNewsFragmentViewPager.setAdapter(new Adapter(getSupportFragmentManager(), fragmentList));

        CircleNavigator circleNavigator = new CircleNavigator(this);


        ScaleCircleNavigator scaleCircleNavigator = new ScaleCircleNavigator(this);

        scaleCircleNavigator.setCircleCount(2);
        scaleCircleNavigator.setNormalCircleColor(Color.LTGRAY);
        scaleCircleNavigator.setSelectedCircleColor(Color.DKGRAY);

        scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() {
            @Override
            public void onClick(int index) {
                mNewsFragmentViewPager.setCurrentItem(index);
            }
        });

        mNewsTabLayout.setNavigator(scaleCircleNavigator);

        mNewsFragmentViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                mNewsTabLayout.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageSelected(int position) {
                mNewsTabLayout.onPageSelected(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                mNewsTabLayout.onPageScrollStateChanged(state);
            }
        });
    }

}
